package cn.aifeix.basic.controller;

import cn.aifeix.basic.dto.EmailCodeDto;
import cn.aifeix.basic.dto.PhoneSmsCodeDto;
import cn.aifeix.basic.service.IVerifyCodeService;
import cn.aifeix.basic.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("/verifyCode")
public class VerifyCodeController {
    @Autowired
    private IVerifyCodeService iVerifyCodeService;

    /**
     * 获取图形验证码
     * @param uuidKey
     * @return
     */
    @GetMapping("/image/{key}")
    public AjaxResult getImageCode(@PathVariable("key") String uuidKey){
        String base64Code = iVerifyCodeService.getImageCode(uuidKey);
        return AjaxResult.me().success(base64Code);
    }
    /**
     * 获取手机验证码
     */
    @PostMapping("/smsCode")
    public AjaxResult smsCode(@RequestBody @Valid PhoneSmsCodeDto dto){
        iVerifyCodeService.smsCode(dto);
        return AjaxResult.me().success();
    }

    /**
     * 获取邮箱验证码
     */
    @PostMapping("/emailCode")
    public AjaxResult emailCode(@RequestBody @Valid EmailCodeDto dto){
        iVerifyCodeService.emailCode(dto);
        return AjaxResult.me().success();
    }
}
